package com.eugene.ui.views;

import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.ViewPart;

import com.eugene.element.FnCalendar;
import com.eugene.entity.MarketVariableDAO;
import com.eugene.enums.EMaturity;

import de.ralfebert.rcputils.builder.table.ColumnBuilder;
import de.ralfebert.rcputils.builder.table.TableViewerBuilder;
import de.ralfebert.rcputils.builder.table.format.Formatter;

public class IrCurveView extends ViewPart {

	private TableViewer tableViewer;
	public IrCurveView() {
	}
	
	@Override
	public void createPartControl(Composite parent) {
		TableViewerBuilder t = new TableViewerBuilder(parent);

		ColumnBuilder baseDate = t.createColumn("BaseDate");
		baseDate.bindToProperty("baseDate");
		baseDate.setPercentWidth(60);
		baseDate.useAsDefaultSortColumn();
		baseDate.makeEditable();
		baseDate.build();
		
		ColumnBuilder ircId = t.createColumn("IrcId");
		ircId.bindToProperty("etyId");
		ircId.setPercentWidth(60);
		ircId.useAsDefaultSortColumn();
		ircId.makeEditable();
		ircId.build();
		
		ColumnBuilder maturity = t.createColumn("Maturity");
		maturity.bindToProperty("maturity");
		maturity.setPercentWidth(60);
		maturity.useAsDefaultSortColumn();
		maturity.makeEditable();
		maturity.build();
		
		ColumnBuilder intRate = t.createColumn("IntRate");
		intRate.bindToProperty("primaryValue");
		intRate.setPercentWidth(60);
		intRate.useAsDefaultSortColumn();
		intRate.makeEditable();
		intRate.build();
		
		
		FnCalendar bDate = new FnCalendar(2010,4,31);
		t.setInput(MarketVariableDAO.getHistoryData("IRKRW_RF",EMaturity.Y01,bDate,10));
		
		tableViewer = t.getTableViewer();
		Formatter.setZebraBackground(tableViewer);
		
//		getSite().getWorkbenchWindow().getSelectionService();
//		getSite().getPage().addSelectionListener("com.eugene.ui.views.MarketVariableView", (ISelectionListener) this);
//		ISelectionListener mylistener = new ISelectionListener() {
//			public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
//				if (sourcepart != IrCurveView.this && selection instanceof IStructuredSelection) {
//				System.out.println("ailoos "+(((IStructuredSelection) selection).toList()));
//				}
//			}
//		};
	}
//	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
//		//Examine selection and act on it!
//	} 
//	void addSelectionListener(ISelectionListener listener){
//	}
//	void removeSelectionListener(ISelectionListener listener){
//	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	
	
}
